package com.xcity.record;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;

import com.xcity.merge.MergeUtil;

public class Player_ext extends BaseRecord{
	public static String SQL_PARA = "id, buildings, buffs, tasks, achievements, financials, pets, pvestages, equips, conquests, skills, adventure, buildings2, attrs, peakroad, resstages, formations, minereports, mines, assists";
	
	public static String COUNT_SQL = "select count(id) from player_ext {0}";
	public static String SELECT_LIMIT = "select * from player_ext {2} limit {0},{1}";
	public static String CONDITION = "WHERE player_ext.id not IN (SELECT player.id FROM player WHERE player.vipLvl = {0} AND player.`level` < {1} AND player.lastLoginTime < \"{2}\")";
	
	public long id;
	public String buildings;
	public String buffs;
	public String tasks;
	public String achievements;
	public String financials;
	public String pets;
	public String pvestages;
	public String equips;
	public String conquests;
	public String skills;
	public String adventure;
	public String buildings2;
	public String attrs;
	public String peakroad;
	public String resstages;
	public String formations;
	public String minereports;
	public String mines;
	public String assists;
	
	@Override
	public void load(ResultSet rs) throws SQLException {
		this.id = rs.getLong(1);
		this.buildings = rs.getString(2);
		this.buffs = rs.getString(3);
		this.tasks = rs.getString(4);
		this.achievements = rs.getString(5);
		this.financials = rs.getString(6);
		this.pets = rs.getString(7);
		this.pvestages = rs.getString(8);
		this.equips = rs.getString(9);
		this.conquests = rs.getString(10);
		this.skills = rs.getString(11);
		this.adventure = rs.getString(12);
		this.buildings2 = rs.getString(13);
		this.attrs = rs.getString(14);
		this.peakroad = rs.getString(15);
		this.resstages = rs.getString(16);
		this.formations = rs.getString(17);
		this.minereports = rs.getString(18);
		this.mines = rs.getString(19);
		this.assists = rs.getString(20);
	}

	@Override
	public String getColumnNames() {
		return SQL_PARA;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append(MergeUtil.toSqlString(id));
		sb.append(", ");
		sb.append(MergeUtil.toSqlString(buildings));
		sb.append(", ");
		sb.append(MergeUtil.toSqlString(buffs));
		sb.append(", ");
		sb.append(MergeUtil.toSqlString(tasks));
		sb.append(", ");
		sb.append(MergeUtil.toSqlString(achievements));
		sb.append(", ");
		sb.append(MergeUtil.toSqlString(financials));
		sb.append(", ");
		sb.append(MergeUtil.toSqlString(pets));
		sb.append(", ");
		sb.append(MergeUtil.toSqlString(pvestages));
		sb.append(", ");
		sb.append(MergeUtil.toSqlString(equips));
		sb.append(", ");
		sb.append(MergeUtil.toSqlString(conquests));
		sb.append(", ");
		sb.append(MergeUtil.toSqlString(skills));
		sb.append(", ");
		sb.append(MergeUtil.toSqlString(adventure));
		sb.append(", ");
		sb.append(MergeUtil.toSqlString(buildings2));
		sb.append(", ");
		sb.append(MergeUtil.toSqlString(attrs));
		sb.append(", ");
		sb.append(MergeUtil.toSqlString(peakroad));
		sb.append(", ");
		sb.append(MergeUtil.toSqlString(resstages));
		sb.append(", ");
		sb.append(MergeUtil.toSqlString(formations));
		sb.append(", ");
		sb.append(MergeUtil.toSqlNameString(minereports));
		sb.append(", ");
		sb.append(MergeUtil.toSqlString(mines));
		sb.append(", ");
		sb.append(MergeUtil.toSqlString(assists));
		return sb.toString();
	}

	@Deprecated
	public static List<Player_ext> getPlayerExtList(Connection conn, int start, int page) throws SQLException{
		List<Player_ext> ret = new ArrayList<Player_ext>();
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			String sql = MessageFormat.format(SELECT_LIMIT, start + "", page + "");
			ps = conn.prepareStatement(sql);
			rs = ps.executeQuery();
			while(rs.next()){
				Player_ext playerEx = new Player_ext();
				playerEx.load(rs);
				ret.add(playerEx);
			}
		} finally {
			if(rs != null){
				rs.close();
			}
			if(ps != null){
				ps.close();
			}
		}
		return ret;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getBuildings() {
		return buildings;
	}

	public void setBuildings(String buildings) {
		this.buildings = buildings;
	}

	public String getBuffs() {
		return buffs;
	}

	public void setBuffs(String buffs) {
		this.buffs = buffs;
	}

	public String getTasks() {
		return tasks;
	}

	public void setTasks(String tasks) {
		this.tasks = tasks;
	}

	public String getAchievements() {
		return achievements;
	}

	public void setAchievements(String achievements) {
		this.achievements = achievements;
	}

	public String getFinancials() {
		return financials;
	}

	public void setFinancials(String financials) {
		this.financials = financials;
	}

	public String getPets() {
		return pets;
	}

	public void setPets(String pets) {
		this.pets = pets;
	}

	public String getPvestages() {
		return pvestages;
	}

	public void setPvestages(String pvestages) {
		this.pvestages = pvestages;
	}

	public String getEquips() {
		return equips;
	}

	public void setEquips(String equips) {
		this.equips = equips;
	}

	public String getConquests() {
		return conquests;
	}

	public void setConquests(String conquests) {
		this.conquests = conquests;
	}

	public String getSkills() {
		return skills;
	}

	public void setSkills(String skills) {
		this.skills = skills;
	}

	public String getAdventure() {
		return adventure;
	}

	public void setAdventure(String adventure) {
		this.adventure = adventure;
	}

	public String getBuildings2() {
		return buildings2;
	}

	public void setBuildings2(String buildings2) {
		this.buildings2 = buildings2;
	}

	public String getAttrs() {
		return attrs;
	}

	public void setAttrs(String attrs) {
		this.attrs = attrs;
	}

	public String getPeakroad() {
		return peakroad;
	}

	public void setPeakroad(String peakroad) {
		this.peakroad = peakroad;
	}

	public String getResstages() {
		return resstages;
	}

	public void setResstages(String resstages) {
		this.resstages = resstages;
	}

	public String getFormations() {
		return formations;
	}

	public void setFormations(String formations) {
		this.formations = formations;
	}

	public String getMinereports() {
		return minereports;
	}

	public void setMinereports(String minereports) {
		this.minereports = minereports;
	}

	public String getMines() {
		return mines;
	}

	public void setMines(String mines) {
		this.mines = mines;
	}

	public String getAssists() {
		return assists;
	}

	public void setAssists(String assists) {
		this.assists = assists;
	}
}
